package com.lyh.miniostudy.controller;

import com.lyh.miniostudy.service.MinioService;
import jakarta.servlet.http.HttpServletResponse;

import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @describe
 * @author liang_yh
 * @since 2024/12/18
 */

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private MinioService minioService;

    @Autowired
    private MongoTemplate mongoTemplate;

    @PostMapping("/upload")
    public String upload(@RequestBody MultipartFile file) throws Exception {
        return minioService.upload(file);
    }


    @GetMapping("download")
    public void download(String file, HttpServletResponse response) {
        minioService.download(response, file);
    }


    @DeleteMapping("/delete")
    public String deleteFile(String file) {
        minioService.delete(file);
        return "success";
    }

    @GetMapping("/test")
    public String test(String file) {
        return "success";
    }
}
